<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>云服务数据平台</title>
    <link rel="stylesheet" type="text/css" href="login/css/index.css"/>
    <script src="jquery/jquery-3.6.0.js"></script>
</head>
<body>
<div class="bg">
    <div class="wel">云服务数据平台</div>
    <div class="user">
        <div style="">用户名</div>
        <input  type="text" name="用户"  placeholder="输入用户名" id="username" />
    </div>
    <div class="password">
        <div>密&nbsp;&nbsp;&nbsp;码</div>
        <input class="" type="password" name="密码" id="password" />
    </div>
    <div class="rem" >
        <input type="checkbox" name="" id="" value="" />
        <div id="reb">
            记住密码
        </div>
    </div>
    <div class="fg" >
        <div style="font-size: 11px;margin-top: 11px;">
            <a style="font-size: 11px;" href="#">忘记密码？</a>
        </div>
    </div>
    <input class="btn" type="button" id="loginButton" name="登录" value="登录" />
</div>
</body>
<script>
    $(function () {
        $("#loginButton").click(function () {
            let username = $("#username").val();
            let password = $("#password").val();
            if(username == null || username === '' ||
                password == null || password === '' ) {
                alert("请输入用户名和密码再登录!");
            }
            else {
                $.ajax({
                    url:"/user/login",   // 请求路径
                    type:"post",            // 请求的方式，不区分大小写
                    cache:false,            // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                    contentType:"application/json;charset=utf-8",
                    data:JSON.stringify({
                        username:username,
                        password:password
                    }),
                    datatype:"json",        // 返回类型，text文本、html页面、json数据
                    success:function(response){
                        console.log("返回: " + response);
                        alert(response.msg);
                        if(response.code === 200) {
                            window.location.href="index.html";
                        }
                    },
                    error:function(response){
                        console.log("出错返回: " + response);
                    }
                });
            }
        });
    });
</script>
</html>
